﻿using PivotCollectionTools.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PivotCollectionTools.Xml;
using System;
using PivotCollectionMaker.WinFormApplication.Controls;
using Moq;
using System.Collections.Generic;

namespace PivotMakerApplicationTdd
{
    
    
    /// <summary>
    ///This is a test class for FacetTest and is intended
    ///to contain all FacetTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CategoryListViewTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Text
        ///</summary>
        [TestMethod()]
        public void CategoryListView_Construct()
        {
            var table = new PivotTable();
            table.Categories.Add(new PivotTableCategory("Class", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Address", PivotTableCellType.Text));
            table.AddColumn("Address");
            table.AddColumn("Class", 9);

            //var view = new MockCategoryListView();

            var columnList = new List<string>();
            var categoryList = new List<string>();

            var mock = new Mock<ICategoryListView>();

            mock.Setup(v => v.ClearCategoryList()).Callback(() => categoryList.Clear());
            mock.Setup(v => v.ClearColumnList()).Callback(() => columnList.Clear());
            mock.Setup(v => v.AddCategoryListItem(It.IsAny<string>()))
                .Callback((string s) => categoryList.Add(s));
            mock.Setup(v => v.AddColumnListItem(It.IsAny<string>()))
                .Callback((string s) => columnList.Add(s));
            mock.Setup(v => v.ShowMessage(It.IsAny<string>(), It.IsAny<string>()))
                .Callback((string message, string caption) => ShowMessage(message, caption));

            var p = new CategoryListPresenter(mock.Object, table);

            int x = categoryList.Count;

            mock.Setup(v => v.SelectedCategoryIndex).Returns(0);
            mock.Setup(v => v.SelectedColumn).Returns("Image Location");

            mock.Raise(v => v.CategoryItemSelected += null, new EventArgs());

            int y = columnList.Count;

            mock.Setup(v => v.RemoveCategory(It.IsAny<int>()))
                .Callback((int index) => categoryList.RemoveAt(index));

            p.DeleteCategory();
            p.DeleteColumn();

            x = categoryList.Count;

            mock.Setup(v => v.SelectedCategoryIndex).Returns(20);
            mock.Setup(v => v.SelectedColumn).Returns("Column Does Not Exist");
            mock.Raise(v => v.CategoryItemSelected += null, new EventArgs());

            p.DeleteCategory();
            p.DeleteColumn();

            //this.view.AddCategoryListItem(item.Name);
            // int SelectedCategoryIndex { get; }
            
            /*
            view.SetViewModel(model);

            view.Add();

            var x = view.ItemCount;

            view.SelectedCategoryIndex = 2;

            view.DeleteSelectedItem();
            view.SelectedCategoryIndex = 1;
            var category = view.SelectedCategory;
            */
        }

        public void ShowMessage(string message, string caption)
        {
            Console.WriteLine(caption);
            Console.WriteLine(message);
        }
    }
}
